/**
 * Apr 25, 2010
 */
package org.tomale.id.projects.ui;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

/**
 * @author ferd
 *
 */
public class ProjectTasksPage extends FormPage {

	public static final String PAGE_ID = "org.tomale.id.projects.ui.editor.project.tasks";
	public static final String PAGE_TITLE = "Tasks";

	ProjectEditorInput _input;
	TreeViewer _viewer;
	
	public ProjectTasksPage(FormEditor editor){
		super(editor,PAGE_ID,PAGE_TITLE);
	}

	@Override
	protected void createFormContent(IManagedForm managedForm) {
		_input = (ProjectEditorInput) getEditorInput();
		
		final ScrolledForm form = managedForm.getForm();
		FormToolkit tk = managedForm.getToolkit();
		Composite body = form.getBody();
		tk.paintBordersFor(body);
		form.setText(this.getTitle());
		
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 2;
		body.setLayout(layout);
		
		createTasksSection(body, tk);
	}
	
	private void createTasksSection(Composite parent, FormToolkit toolkit){
		Section section = toolkit.createSection(parent,
				Section.DESCRIPTION | Section.TITLE_BAR | Section.EXPANDED);
		section.setText("General Information");
		section.setDescription("This section describes general information about this project.");
		TableWrapData td = new TableWrapData(TableWrapData.FILL);
		section.setLayoutData(td);
		
		Composite comp = toolkit.createComposite(section);
		toolkit.paintBordersFor(comp);
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		comp.setLayout(layout);
		
		Label l;
		
		// list of tasks
//		l = toolkit.createLabel(comp, "Tasks");
//		l.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		_viewer = new TreeViewer(comp);
		_viewer.setContentProvider(new ContentProvider());
		_viewer.setLabelProvider(new TreeLabelProvider());
		toolkit.adapt(_viewer.getTree());
		initTree(_viewer.getTree());

		Button add = toolkit.createButton(comp, "Add", SWT.PUSH);
		add.setToolTipText("Add task");
		add.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		Button remove = toolkit.createButton(comp, "Remove", SWT.PUSH);
		remove.setToolTipText("Remove task");
		remove.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		Button up = toolkit.createButton(comp, "Up", SWT.PUSH);
		up.setToolTipText("Move task up");
		up.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		Button down = toolkit.createButton(comp, "Down", SWT.PUSH);
		down.setToolTipText("Move task down");
		down.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		Button right = toolkit.createButton(comp, "Right", SWT.PUSH);
		right.setToolTipText("Move task right");
		right.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		Button left = toolkit.createButton(comp, "Left", SWT.PUSH);
		left.setToolTipText("Left");
		left.setLayoutData(new GridData(SWT.FILL,SWT.FILL,false,false));
		
		section.setClient(comp);
	}
	
	private void initTree(Tree tree){
		tree.setHeaderVisible(true);
		tree.setLinesVisible(true);
		tree.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false,1,6));
		
		TreeColumn col;
		
		// name
		col = new TreeColumn(tree, SWT.NONE);
		col.setText("Name");
		col.setToolTipText("Task name");
		col.setWidth(100);
		col.setResizable(true);
		col.setMoveable(true);
	}

	class ContentProvider implements ITreeContentProvider {

		@Override
		public Object[] getChildren(Object parentElement) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public Object getParent(Object element) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public boolean hasChildren(Object element) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public Object[] getElements(Object inputElement) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void dispose() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			// TODO Auto-generated method stub
			
		}
		
	}

	class TreeLabelProvider extends LabelProvider implements ITableLabelProvider {

		@Override
		public Image getColumnImage(Object element, int columnIndex) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public String getColumnText(Object element, int columnIndex) {
			// TODO Auto-generated method stub
			return null;
		}
		
	}
}
